package object;

import java.util.ArrayDeque;
import java.util.Deque;
import java.util.LinkedList;
import java.util.Queue;

public class MyArrayQueue {
    //基于数组实现循环队列
    private int head;
    private int tail;
    private int size;
    private String[] arr;
    public MyArrayQueue() {
        arr = new String[1000];
    }
    public MyArrayQueue(int capacity) {
        arr = new String[capacity];
    }
    public void offer(String val) {
        if(size == arr.length) {
            return;
        }
        arr[tail] = val;
        tail++;
//        if(tail == arr.length) {
//            tail = 0;
//        }
        //还有另外一种写法:更新下标
        tail = (tail + 1) % arr.length;
        size++;
    }
    public String poll() {
        if(size == 0) {
            return null;
        }
        String val = arr[head];
        head++;
        if(head == arr.length) {
            head = 0;
        }
        size--;
        return val;
    }
    public String peek() {
        if(size == 0) {
            return null;
        }
        return arr[head];

    }
    public boolean isEmpty() {
        return size == 0;

    }
    public int size() {
        return size;

    }

    public static void main(String[] args) {
        //基于数组实现
        //Queue<Integer> queue = new ArrayDeque<>();

        //双端队列实现的两种方式
        Deque<Integer> deque = new ArrayDeque<>();
        Deque<Integer> deque1 = new LinkedList<>();


    }
}
